﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;

namespace PcArduinoControl
{
	public class IncorrectDigitalIoPinTypeException :
		ArgumentException
	{
		const string cDefaultMessage =
			"The digital IO pin type for this operation is incorrect.";

		const string cDefaultMessagePinInput =
			"Tried to use an input digital IO pin as an output.";

		const string cDefaultMessagePinOutput =
			"Tried to use an output digital IO pin as an input.";

		const string cDefaultMessagePinUnconfigured =
			"Tried to use an unconfigured digital IO pin as a configured pin.";

		private static string GetDefaultMessage(PinType pinType)
		{
			switch (pinType)
			{
				case PinType.Input:
					return cDefaultMessagePinInput;
				case PinType.Output:
					return cDefaultMessagePinOutput;
				case PinType.Unconfigured:
					return cDefaultMessagePinUnconfigured;
				default:
					return cDefaultMessage;
			}
		}

		public byte PinNumber { get; protected set; }
		public PinType PinType { get; protected set; }

		public IncorrectDigitalIoPinTypeException() :
			base(cDefaultMessage)
		{ }

		public IncorrectDigitalIoPinTypeException(string message) :
			base(message)
		{ }

		public IncorrectDigitalIoPinTypeException(string message, Exception innerException) :
			base(message, innerException)
		{ }

		public IncorrectDigitalIoPinTypeException(byte pinNumber) :
			base(cDefaultMessage)
		{
			PinNumber = pinNumber;
		}

		public IncorrectDigitalIoPinTypeException(byte pinNumber, PinType pinType) :
			base(GetDefaultMessage(pinType))
		{
			PinNumber = pinNumber;
			PinType = pinType;
		}

		public IncorrectDigitalIoPinTypeException(string message, byte pinNumber) :
			base(message)
		{
			PinNumber = pinNumber;
		}

		public IncorrectDigitalIoPinTypeException(string message, byte pinNumber, PinType pinType) :
			base(message)
		{
			PinNumber = pinNumber;
			PinType = pinType;
		}

		public IncorrectDigitalIoPinTypeException(string message, Exception innerException, byte pinNumber) :
			base(message, innerException)
		{
			PinNumber = pinNumber;
		}

		public IncorrectDigitalIoPinTypeException(string message, Exception innerException, byte pinNumber, PinType pinType) :
			base(message, innerException)
		{
			PinNumber = pinNumber;
			PinType = pinType;
		}

		protected IncorrectDigitalIoPinTypeException(SerializationInfo info, StreamingContext context) :
			base(info, context)
		{ }
	}
}
